Search
Cell.valueAs(T) Method
See Also
 






Down-casts the cell value to specified type.

Namespace: com.mindfusion.spreadsheet
Package: com.mindfusion.spreadsheet

 Syntax

Java  Copy Code

public <T> T valueAs (
    Class<T> type
)

 Parameters

type

A Class instance specifying the target type.

 Return Value

The cell value cast to specified type, or null if it's of a different type.

 Remarks

Syntax sugar for a slightly shorter type checking and casting.

 Example

Java  Copy Code

double total = 0;

public void cellClicked(CellMouseEvent e)
{
    Double value = e.getCell().valueAs(Double.class);
    if (value != null)
        total += value.doubleValue();
}

// alternative to

public void cellClicked(CellMouseEvent e)
{
    if (e.getCell().getValue() instanceof Double)
    {
        Double value = (Double)e.getCell().getValue();
        total += value.doubleValue();
    }
}

 See Also